"""
# -*- coding: utf-8 -*-
# @Time    : 2023/5/21 19:59
# @Author  : 王摇摆
# @FileName: RegressionDecisionTreeVisual.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
from DecisionTree.GainTree.RegressionData import *
from DecisionTree.GainTree.RegressionDecisionTree import *

# 训练决策树回归模型
# regressorTree = RegressorTree() #
regressorTree = RegressorTree(max_depth=3, min_samples_leaf=5) # 决策树进行正则化，减轻过拟合
regressorTree.fit(X, y)

# 指定中文字体文件的路径
font_path = 'C:\Windows\Fonts\simkai.ttf'
# 加载中文字体
font = FontProperties(fname=font_path)

# 决策树回归的可视化
fig, ax = plt.subplots()
ax.set_facecolor('#f8f9fa')

x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
xx = np.arange(x_min, x_max, .05)
yy = regressorTree.predict(np.c_[xx.ravel()])

plt.scatter(X, y, c='#e63946', marker='o', s=20)
plt.plot(xx, yy)

ax.set_title('决策树回归', color='#264653',font=font,fontsize=16)
ax.set_xlabel('X', color='#264653')
ax.set_ylabel('Y', color='#264653')
ax.tick_params(labelcolor='#264653')
plt.show()
